/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean;

import java.util.ArrayList;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import org.primefaces.event.map.OverlaySelectEvent;
import org.primefaces.model.map.DefaultMapModel;
import org.primefaces.model.map.LatLng;
import org.primefaces.model.map.MapModel;
import org.primefaces.model.map.Marker;

/**
 *
 * @author akay
 */
@ManagedBean
@SessionScoped
public class MapBean {

    private MapModel simpleModel;
    private Marker marker;
    
    public MapBean() {
        
        simpleModel = new DefaultMapModel();  
       
            
        
        ArrayList<Location> al;
                al=new DBGetData().getLocations();
        
        for (int i = 0; i < al.size(); i++) {
            simpleModel.addOverlay(new Marker(new LatLng(Double.parseDouble(al.get(i).getLattitude()),Double.parseDouble(al.get(i).getLongtitude())), al.get(i).getDeviceID()));
            
        }
        
       
        
    }
    
     public MapModel getSimpleModel() {  
        return simpleModel;  
    }  
      
    public void onMarkerSelect(OverlaySelectEvent event) {  
        marker = (Marker) event.getOverlay();  
          
        addMessage(new FacesMessage(FacesMessage.SEVERITY_INFO, "Marker Selected", marker.getTitle()));  
    }  
      
    public Marker getMarker() {  
        return marker;  
    }  
      
    public void addMessage(FacesMessage message) {  
        FacesContext.getCurrentInstance().addMessage(null, message);  
    }  
}
